from pymysql import Connection
conn = None
try:
    conn = Connection(
        host="localhost",
        port=3306,
        user="root",
        passwd="root",
        charset="utf8",
        database="db2",
    )

    cursor = conn.cursor()

    sql="""
        create table user(
            id int primary key auto_increment,
            name varchar(20) not null,
            gender varchar(20)
            age int,
            address varchar(20)
        )
    """


    cursor.execute(sql)
    print('表创建成功')

except Exception as e:
    print(e)
finally:
    if conn:
        conn.close()


